package org.jeecg.modules.zcgl.service.impl;

import org.jeecg.modules.zcgl.entity.LeaseContractContent;
import org.jeecg.modules.zcgl.mapper.LeaseContractContentMapper;
import org.jeecg.modules.zcgl.service.ILeaseContractContentService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * @Description: 合同打印信息
 * @Author: jeecg-boot
 * @Date:   2021-01-13
 * @Version: V1.0
 */
@Service
public class LeaseContractContentServiceImpl extends ServiceImpl<LeaseContractContentMapper, LeaseContractContent> implements ILeaseContractContentService {

    @Override
    public boolean saveCheck(LeaseContractContent leaseContractContent) {
        LeaseContractContent content = baseMapper.selectByLeaseContractIdAndPrintTemplateId(leaseContractContent.getLeaseContractId(), leaseContractContent.getPrintTemplateId());
        if (content == null){
            content = new LeaseContractContent();
            BeanUtils.copyProperties(leaseContractContent, content);
            content.setPrintNum(1);
            baseMapper.insert(content);
        } else {
            content.setPrintNum(content.getPrintNum() + 1);
            baseMapper.updateById(content);
        }
        return true;
    }

    @Override
    public LeaseContractContent selectByLeaseContractIdAndPrintTemplateId(String leaseContractId, String printTemplateId) {
        return baseMapper.selectByLeaseContractIdAndPrintTemplateId(leaseContractId, printTemplateId);
    }
}
